Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduces is* functions for strings #3432

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

ancailliau
Copy link

Introduces additional functions for testing strings. These are generally faster and more readable than their regular expression equivalent. I found those useful when writing rapid power-ups and integrations with 3rd party services.

Methods are a direct mapping from their Python equivalent

  • isalnum()
  • isalpha()
  • isascii()
  • isdecimal()
  • isdigit()
  • isidentifier()
  • islower()
  • isnumeric()
  • isprintable()
  • isspace()
  • istitle()
  • isupper()

@vEpiphyte vEpiphyte added enhancement reqChangelog requires changelog labels Nov 17, 2023
synapse/lib/stormtypes.py Outdated Show resolved Hide resolved
@ancailliau
Copy link
Author

I missed the notification. I updated according to the review.

@vEpiphyte vEpiphyte added this to the v2.16x.x milestone Apr 18, 2024
Copy link
Contributor

@vEpiphyte vEpiphyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ancailliau Can you please apply the following patch to get tests passing?

diff --git a/synapse/lib/stormtypes.py b/synapse/lib/stormtypes.py
index 354dac361..37da9ab18 100644
--- a/synapse/lib/stormtypes.py
+++ b/synapse/lib/stormtypes.py
@@ -4409,8 +4409,8 @@ class Str(Prim):
 
                     $foo="aca123" return ( $foo.isAlnum() ) // true
             ''',
-         'type': {'type': 'function', '_funcname': '_methStrIsAlnum',
-                  'returns': {'type': 'bool', 'desc': 'Whether string is alphanumeric', }}},
+         'type': {'type': 'function', '_funcname': '_methStrIsAlNum',
+                  'returns': {'type': 'boolean', 'desc': 'Whether string is alphanumeric', }}},
          {'name': 'isAlpha', 'desc': '''
             Returns true if all chars in the string are in the alphabet, false otherwise.
 
@@ -4420,7 +4420,7 @@ class Str(Prim):
                     $foo="aca" return ( $foo.isAlpha() ) // true
             ''',
          'type': {'type': 'function', '_funcname': '_methStrIsAlpha',
-                  'returns': {'type': 'bool', 'desc': 'Whether string only contains chars from alphabet', }}},
+                  'returns': {'type': 'boolean', 'desc': 'Whether string only contains chars from alphabet', }}},
          {'name': 'isAscii', 'desc': '''
             Returns true if all chars in the string are ASCII chars, false otherwise.
 
@@ -4430,7 +4430,7 @@ class Str(Prim):
                     $foo="aca" return ( $foo.isAscii() ) // true
             ''',
          'type': {'type': 'function', '_funcname': '_methStrIsASCII',
-                  'returns': {'type': 'bool', 'desc': 'Whether all the chars are ASCII', }}},
+                  'returns': {'type': 'boolean', 'desc': 'Whether all the chars are ASCII', }}},
          {'name': 'isDecimal', 'desc': '''
             Returns true if all the chars are decimals (including unicode), false otherwise.
 
@@ -4440,7 +4440,7 @@ class Str(Prim):
                     $foo="123" return ( $foo.isDecimal() ) // true
             ''',
          'type': {'type': 'function', '_funcname': '_methStrIsDecimal',
-                  'returns': {'type': 'bool', 'desc': 'Whether all the chars are decimals', }}},
+                  'returns': {'type': 'boolean', 'desc': 'Whether all the chars are decimals', }}},
          {'name': 'isDigit', 'desc': '''
             Returns true if all the chars are decimals, false otherwise.
             Exponents are considered as digits.
@@ -4451,7 +4451,7 @@ class Str(Prim):
                     $foo="123" return ( $foo.isDigit() ) // true
             ''',
          'type': {'type': 'function', '_funcname': '_methStrIsDigit',
-                  'returns': {'type': 'bool', 'desc': 'Whether all the chars are digits', }}},
+                  'returns': {'type': 'boolean', 'desc': 'Whether all the chars are digits', }}},
          {'name': 'isIdentifier', 'desc': '''
             Returns true if the string is a valid identifier, false otherwise.
             A valid identifier only contains alphanumeric letters (a-z) and (0-9), or underscores (_).
@@ -4463,7 +4463,7 @@ class Str(Prim):
                     $foo="aca_123" return ( $foo.isIdentifier() ) // true
             ''',
          'type': {'type': 'function', '_funcname': '_methStrIsIdentifier',
-                  'returns': {'type': 'bool', 'desc': 'Whether the string is a valid identifier', }}},
+                  'returns': {'type': 'boolean', 'desc': 'Whether the string is a valid identifier', }}},
          {'name': 'isLower', 'desc': '''
             Returns true if all the chars are in lower case, false otherwise.
             Numbers, symbols and spaces are not checked, only alphabet characters.
@@ -4474,7 +4474,7 @@ class Str(Prim):
                     $foo="aca" return ( $foo.isLower() ) // true
             ''',
          'type': {'type': 'function', '_funcname': '_methStrIsLower',
-                  'returns': {'type': 'bool', 'desc': 'Whether all chars are in lower case', }}},
+                  'returns': {'type': 'boolean', 'desc': 'Whether all chars are in lower case', }}},
          {'name': 'isNumeric', 'desc': '''
             Returns true if all the chars are numeric, false otherwise.
             Unicode fractions are considered as numeric, but not decimals like `1.5`.
@@ -4485,7 +4485,7 @@ class Str(Prim):
                     $foo="123" return ( $foo.isNumeric() ) // true
             ''',
          'type': {'type': 'function', '_funcname': '_methStrIsNumeric',
-                  'returns': {'type': 'bool', 'desc': 'Whether all chars are numeric', }}},
+                  'returns': {'type': 'boolean', 'desc': 'Whether all chars are numeric', }}},
          {'name': 'isPrintable', 'desc': '''
             Returns true if all the chars are printable, false otherwise.
 
@@ -4495,7 +4495,7 @@ class Str(Prim):
                     $foo="aca 123" return ( $foo.isPrintable() ) // true
             ''',
          'type': {'type': 'function', '_funcname': '_methStrIsPrintable',
-                  'returns': {'type': 'bool', 'desc': 'Whether all chars are printable', }}},
+                  'returns': {'type': 'boolean', 'desc': 'Whether all chars are printable', }}},
          {'name': 'isSpace', 'desc': '''
             Returns true if all the chars are whitespaces, false otherwise.
 
@@ -4505,7 +4505,7 @@ class Str(Prim):
                     $foo="   " return ( $foo.isSpace() ) // true
             ''',
          'type': {'type': 'function', '_funcname': '_methStrIsSpace',
-                  'returns': {'type': 'bool', 'desc': 'Whether all chars are whitespaces', }}},
+                  'returns': {'type': 'boolean', 'desc': 'Whether all chars are whitespaces', }}},
          {'name': 'isTitle', 'desc': '''
             Returns true if all words in a text start with a upper case letter and others are lower case, false otherwise.
 
@@ -4515,7 +4515,7 @@ class Str(Prim):
                     $foo="Aca Test" return ( $foo.isTitle() ) // true
             ''',
          'type': {'type': 'function', '_funcname': '_methStrIsTitle',
-                  'returns': {'type': 'bool', 'desc': 'Whether all words starts with an upper case', }}},
+                  'returns': {'type': 'boolean', 'desc': 'Whether all words starts with an upper case', }}},
          {'name': 'isUpper', 'desc': '''
             Returns true if all the characters are in upper case, false otherwise.
             Numbers, symbols and spaces are not checked, only alphabet characters.
@@ -4526,7 +4526,7 @@ class Str(Prim):
                     $foo="ACA" return ( $foo.isUpper() ) // true
             ''',
          'type': {'type': 'function', '_funcname': '_methStrIsUpper',
-                  'returns': {'type': 'bool', 'desc': 'Whether all chars are upper case', }}},
+                  'returns': {'type': 'boolean', 'desc': 'Whether all chars are upper case', }}},
     )
     _storm_typename = 'str'
     _ismutable = False

@vEpiphyte vEpiphyte modified the milestones: v2.168.0, v2.16x.x, v2.169.0, v2.170.0 May 2, 2024
@Cisphyx Cisphyx modified the milestones: v2.170.0, v2.171.0 May 30, 2024
@vEpiphyte vEpiphyte removed this from the v2.171.0 milestone Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement reqChangelog requires changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants